package spe.ui.editor.policy;

import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.DirectEditPolicy;
import org.eclipse.gef.requests.DirectEditRequest;

import spe.model.spem.SPEMElement;
import spe.ui.editor.command.ElementRenameCommand;
import spe.ui.editor.figure.SPEFigure;

public class ElementDirectEditPolicy extends DirectEditPolicy
{

	@Override
	protected Command getDirectEditCommand(DirectEditRequest rq) 
	{
		ElementRenameCommand cmd = new ElementRenameCommand((String)rq.getCellEditor().getValue(), (SPEMElement)getHost().getModel());
		return cmd;
	}

	@Override
	protected void showCurrentEditValue(DirectEditRequest rq) 
	{
		String value = (String)rq.getCellEditor().getValue();
		((SPEFigure)getHostFigure()).getNameLabel().setText(value);
	}

}
